/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: lucky
 * Date: 2022-08-29
 * Time: 14:46
 */
public class Tree {
//    public TreeNode root;
    public class TreeNode {
        public char val;
        public TreeNode left;
        public TreeNode right;

        public TreeNode(char val) {
            this.val = val;
        }
    }


    /**
     * 手动创建一个二叉树，返回它的根节点
     *
     * @return
     */
    public TreeNode cretaTree() {
        TreeNode A = new TreeNode('A');
        TreeNode B = new TreeNode('B');
        TreeNode C = new TreeNode('C');
        TreeNode D = new TreeNode('D');
        TreeNode E = new TreeNode('E');
        TreeNode F = new TreeNode('F');
        TreeNode G = new TreeNode('G');
        TreeNode H = new TreeNode('H');
        TreeNode I = new TreeNode('I');
        A.left = B;
        A.right = C;
        B.left = D;
        B.right = E;
        D.left = H;
        C.left = F;
        C.right = G;
        G.right = I;
        return A;
    }

    /**
     *
     * 前序、中序、后序遍历二叉树
     */
    //前序遍历
    public void preOder(TreeNode root){
        if(root == null) return;
        System.out.print(root.val+" ");
        preOder(root.left);
        preOder(root.right);
    }
    //中序遍历
    public void inOder(TreeNode root){
        if (root == null) return;
        inOder(root.left);
        System.out.print(root.val+" ");
        inOder(root.right);

    }
    //后序遍历
    public void lastOder(TreeNode root){
        if (root == null) return;
        lastOder(root.left);
        lastOder(root.right);
        System.out.print(root.val+" ");
    }
}

